package com.haiwei.poi.word.test;

import com.haiwei.poi.common.HaiweiListUtils;
import com.haiwei.poi.word.bean.HaiweiBeanUtil;
import com.haiwei.poi.word.common.HaiweiDocumentGenerator;
import com.haiwei.poi.word.poi.HaiweiParagraphUtil;
import com.haiwei.poi.word.poi.HaiweiXWPFTableUtil;
import org.apache.poi.xwpf.usermodel.*;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 1.
 *
 * @date: 2022-06-25
 * @version: 1.0
 * @author: karry@haiwei.com
 */
public class test1 {
    public static void main(String[] args) {
        try {
        	
            final XWPFDocument document = HaiweiDocumentGenerator
                    .build(new File(FilePathUtils.getPath("11.docx")));
            
            Map<String, Object> map = new HashMap<>();
            map.put("aa","aa111");
            Map<String, Object> map1 = new HashMap<>();
            map.put("客户",map1);
            map.put("customer",map1);
            map1.put("名称","客户名称");
            map1.put("customerName","customer1111");
            HaiweiBeanUtil.setBean(map);
    
            // 页眉
            final List<XWPFHeader> headerList = document.getHeaderList();
            if(HaiweiListUtils.isNotBlank(headerList)){
                for(XWPFHeader header : headerList){
                    HaiweiParagraphUtil.pause(header.getParagraphs());
                    HaiweiXWPFTableUtil.parse(header.getTables());
                }
            }
            
            // 页脚
            final List<XWPFFooter> footerList = document.getFooterList();
            if(HaiweiListUtils.isNotBlank(footerList)){
                for(XWPFFooter footer : footerList){
                    HaiweiParagraphUtil.pause(footer.getParagraphs());
                    HaiweiXWPFTableUtil.parse(footer.getTables());
                }
            }
    
            // 处理
            List<XWPFParagraph> paragraphs = document.getParagraphs();
            HaiweiParagraphUtil.pause(paragraphs);
            HaiweiXWPFTableUtil.parse(document.getTablesIterator());
    
            final File file = new File(FilePathUtils.getPath("1111.docx"));
            HaiweiDocumentGenerator.toFile(document,file);
            System.out.println(file.getAbsolutePath());
            
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    
    
}
